Mindex Metamethod
The __mindex metamethod stands for 'method index'. It has a secondary priority to __index and it's only invoked when the lookup is being performed by method invocation syntax. This is used to avoid compatibility issues regarding Pluto's default metatable for tables. For example:
plutolocal t = { "a", "b", "c" }print(t:concat()) --> abc
In this code, the following occurs:
concatkey is not directly present in the table, so__indexis queried.__indexreturns nil.- Since
__indexreturned nil and this lookup is being performed by method invocation syntax (:),__mindexis queried.
An example showing how __mindex is walked recursively so :insert still works with a custom __mindexplutolocal t = setmetatable({}, {__mindex = {function sum()local accum = 0for self as v doaccum += vendreturn accumend}})t:insert(1)t:insert(2)print(t.sum) --> nilprint(t:sum()) --> 3
An example of a field taking precedenceplutolocal t = { 1, 2 }print(t:min()) --> 1t.min = 1print(t:min()) -- attempt to call a number value